﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using QMSDAL;

namespace QuaManSys
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取查询字符串里的员工号
            string strId = Request.QueryString["employeeId"];
            if (strId != null)
            {
                //获取用户的Id、name、department
                CurUser curUser = Users.GetCurUser(strId);               
                if (curUser.employeeId != null || curUser.employeeId != "")
                {
                    Session.Add("curUser", curUser);
                }
                else
                {
                    Response.Redirect("Login.aspx");
                }
                Response.Redirect("MainPage.aspx");
            }
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //获取登录用户的账号和密码
                string strName = txtName.Text;
                string strPwd = txtPwd.Text;
                if (strName != null && strPwd != null)
                {
                    //获取用户的Id、name、department
                    CurUser curUser = Users.GetCurUser(strName, strPwd);
                    if (curUser.employeeId != null || curUser.employeeId != "")
                    {
                        Session.Add("curUser", curUser);
                        Response.Redirect("MainPage.aspx");
                    }
                }
                else
                {
                    txtName.Text = "";
                    txtPwd.Text = "";
                }
            }
            catch 
            {
                txtName.Text = "";
                txtPwd.Text = "";
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtName.Text = "";
            txtPwd.Text = "";
        }
    }
}